﻿@model ZSZ.AdminWeb.Models.AdminUser.AdminUserGetAddModel
@{
    ViewBag.Title = "添加管理员";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<form id="formData">
    <div class="row cl">
        <label class="form-label col-3"><span class="c-red">*</span>名字：</label>
        <div class="formControls col-5">
            <input type="text" class="input-text" name="name" id="name" datatype="*1-50" nullmsg="管理员名称不能为空" />
        </div>
        <div class="col-4"> </div>
    </div>
    <div class="row cl">
        <label class="form-label col-3"><span class="c-red">*</span>手机号：</label>
        <div class="formControls col-5">
            <input type="text" class="input-text" name="phoneNum" id="name" datatype="*1-50" nullmsg="手机号不能为空" />
        </div>
        <div class="col-4"> </div>
    </div>
    <div class="row cl">
        <label class="form-label col-3"><span class="c-red">*</span>密码：</label>
        <div class="formControls col-5">
            <input type="text" class="input-text" name="pass" id="name" datatype="*1-50" nullmsg="密码不能为空" />
        </div>
        <div class="col-4"> </div>
    </div>
    <div class="row cl">
        <label class="form-label col-3"><span class="c-red">*</span>邮箱：</label>
        <div class="formControls col-5">
            <input type="text" class="input-text" name="email" id="name" datatype="*1-50" nullmsg="邮箱不能为空" />
        </div>
        <div class="col-4"> </div>
    </div>
    <div class="row c1">
        <label class="form-label col-3"><span class="c-red">*</span>城市：</label>
        <div class="formControls col-5">
            <select name="cityId">
                <option value="0">总部</option>
                @foreach (var item in Model.Cities)
                {
                    <option value="@item.Id">@item.Name</option>
                }
            </select>
        </div>
        <div class="col-4"> </div>
    </div>
    <div class="row cl">
        @foreach (var perm in Model.Roles)
        {
            <div class="col-xs-12 col-sm-3">
                <input type="checkbox" id="roleIds_@perm.Id" name="roleIds" value="@perm.Id" />
                <label for="roleIds_@perm.Id">@perm.Name</label>
            </div>
        }
    </div>
    <input type="button" value="添加" id="save" />
</form>

@section footerjs{
    <script src="~/js/Validform_v5.3.2.js"></script>
    <script type="text/javascript">
        function add() {
            var fromData = $('#formData').serializeArray();
            $.ajax({
                url: '/AdminUser/Add',
                data: fromData,
                dataType: 'json',
                type: 'post',
                success: function (res) {
                    if (res.status == 'ok') {
                        parent.location.reload();
                    } else {
                        alert(res.errorMsg);
                    }
                },
                error: function () {
                    alert('网络请求错误');
                }
            })
        }
        $(function () {
            var demo = $("#formData").Validform({ tiptype: 2 });
            $('#save').click(function () {
                if (demo.check(false)) {
                    add();
                }
            })
        })
    </script>
}

